var gl_vue_vm_list_inventory_html = $('#vue_vm_list_inventory').html();

$(function() {
	$('#vue_vm_list_inventory div').hide();
});

var elderPayRecord = {
	elderPayRecordId: '',
	costDesc: '',
	elderId: '',
	elderName: '',
	elderCardId: '',
	payMoney: '',
	payDate: '',
	createTime: '',
	updateTime: '',
	remark: '',
	payStatus: '',
	payWay: '',
	relationId: '',
	costType: '',
	subjectRoomId: '',
	payType: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	subjectRoomId: getLoginedUser()? getLoginedUser().subjectRoomId: '',
	subjectRoomName: getLoginedUser()? getLoginedUser().subjectRoomName: ''
};

var view = {
	data: elderPayRecord
};

if($('#vue_vm').length > 0) {
	var vue_vm = new Vue({
		el: '#vue_vm',
		data: view
	});
}

function elderPayRecord_findInventoryBySearchVal(operation_type) {
	if($('#vue_vm_list_inventory div').length==0) {return;}
	$('#vue_vm_list_inventory div').hide();
	var param = {};
	param.searchVal = $('input:radio[name="elderId"]:checked').attr('cardId');
	if(isEmpty(param.searchVal)) {
		alert('请查询并选择长者');
		return;
	}
	
	switch(operation_type) {
		case 1:
			//param.searchVal = $('#searchVal_1').val();
			
			break;
		case 2:
			//param.searchVal = $('#searchVal_2').val();
			var year = $('#year').val();
			var month = $('#month').val();
			
			if(isEmpty(year)) {
				alert('请输入年');
				return;
			}
			if(isEmpty(month)) {
				alert('请选择月');
				return;
			}
			
			param.yearMonth = getStandardMonth(year, month);
			break;
	}
	
	find_basic_by_json(path+'/elderPayRecord/findInventoryBySearchVal', param, function(response) {
		$('#vue_vm_list_inventory').html(gl_vue_vm_list_inventory_html);
		
		new Vue({
			el: '#vue_vm_list_inventory',
			data: {
				todos: response.data
			},
			methods: {
				getTitle:function() {
					var text = '';
					if(operation_type==1) {
						text = '全部';
					}else {
						text = year+'年'+month+'月';
					}
					
					return text;
				},
				openTotalPage:function() {
					openTotalPage_buda(elderBeHospital.beHospitalId);
				},
				openPrintPage:function(paperType) {
					openPrintPage_buda(elderBeHospital.beHospitalId, paperType);
				},
				getElderPayRecordTotalMoney:function(forms) {
					var totalMoney = 0;
					
					if(forms) {
						for(var i=0; i<forms.length; i++) {
                            if(forms[i].payWay==3){//如果是vip卡扣费
                                continue;
                            }
							totalMoney += forms[i].payMoney;
						}
					}
					
					return totalMoney;
				},
				getElderArrearageTotalMoney:function(forms) {
					var totalMoney = 0;
					
					if(forms) {
						for(var i=0; i<forms.length; i++) {
							totalMoney += forms[i].arrearageMoney;
						}
					}
					
					return totalMoney;
				}
			}
		});
		
		$('#vue_vm_list_inventory div').show();
	});
}

function elderPayRecord_findMonthInventory() {
	if($('#vue_vm_list_inventory div').length==0) {return;}
	$('#vue_vm_list_inventory div').hide();
	var year = $('#year').val();
	var month = $('#month').val();
	
	if(isEmpty(elderBeHospital.beHospitalId)) {
		alert('请选择长者');
		return;
	}
	if(elderBeHospital.beHospitalId=='beHospitalId-none') {
		alert('该长者未入住');
		return;
	}
	if(isEmpty(year)) {
		alert('请输入年');
		return;
	}
	if(isEmpty(month)) {
		alert('请选择月');
		return;
	}
	
	var yearMonth = getStandardMonth(year, month);

	find_basic_by_json(path+'/elderPayRecord/findMonthInventory', {month:yearMonth, beHospitalId:elderBeHospital.beHospitalId}, function(response) {
		$('#vue_vm_list_inventory').html(gl_vue_vm_list_inventory_html);
		
		new Vue({
			el: '#vue_vm_list_inventory',
			data: {
				todos: response.data
			},
			methods: {
				getTitle:function() {
					return year+'年'+month+'月';
				},
				openTotalPage:function() {
					openTotalPageByMonth(elderBeHospital.beHospitalId, yearMonth);
				},
				openPrintPage:function(paperType) {
					openPrintPageByMonth(elderBeHospital.beHospitalId, yearMonth, paperType);
				},
				getElderPayRecordTotalMoney:function(forms) {
					var totalMoney = 0;
					
					if(forms) {
						for(var i=0; i<forms.length; i++) {
                            if(forms[i].payWay==3){//如果是vip卡扣费
                                continue;
                            }
							totalMoney += forms[i].payMoney;
						}
					}
					
					return totalMoney;
				},
				getElderArrearageTotalMoney:function(forms) {
					var totalMoney = 0;
					
					if(forms) {
						for(var i=0; i<forms.length; i++) {
							totalMoney += forms[i].arrearageMoney;
						}
					}
					
					return totalMoney;
				}
			}
		});
		
		$('#vue_vm_list_inventory div').show();
	});
}

function elderPayRecord_findDayInventory() {
	if($('#vue_vm_list_inventory div').length==0) {return;}
	$('#vue_vm_list_inventory div').hide();
	var year = $('#year').val();
	var month = $('#month').val();
	var day = $('#day').val();
	
	if(isEmpty(elderBeHospital.beHospitalId)) {
		alert('请选择长者');
		return;
	}
	if(elderBeHospital.beHospitalId=='beHospitalId-none') {
		alert('该长者未入住');
		return;
	}
	if(isEmpty(year)) {
		alert('请输入年');
		return;
	}
	if(isEmpty(month)) {
		alert('请选择月');
		return;
	}
	if(isEmpty(day)) {
		alert('请选择日');
		return;
	}
	
	var yearMonthDay = getStandardDay(year, month, day);

	find_basic_by_json(path+'/elderPayRecord/findDayInventory', {day:yearMonthDay, beHospitalId:elderBeHospital.beHospitalId}, function(response) {
		$('#vue_vm_list_inventory').html(gl_vue_vm_list_inventory_html);
		
		new Vue({
			el: '#vue_vm_list_inventory',
			data: {
				todos: response.data
			},
			methods: {
				getTitle:function() {
					return year+'年'+month+'月'+day+'日';
				},
				openTotalPage:function() {
					openTotalPageByDay(elderBeHospital.beHospitalId, yearMonthDay);
				},
				openPrintPage:function(paperType) {
					openPrintPageByDay(elderBeHospital.beHospitalId, yearMonthDay, paperType);
				},
				getElderPayRecordTotalMoney:function(forms) {
					var totalMoney = 0;
					
					if(forms) {
						for(var i=0; i<forms.length; i++) {
                            if(forms[i].payWay==3){//如果是vip卡扣费
                                continue;
                            }
							totalMoney += forms[i].payMoney;
						}
					}
					
					return totalMoney;
				},
				getElderArrearageTotalMoney:function(forms) {
					var totalMoney = 0;
					
					if(forms) {
						for(var i=0; i<forms.length; i++) {
							totalMoney += forms[i].arrearageMoney;
						}
					}
					
					return totalMoney;
				}
			}
		});
		
		$('#vue_vm_list_inventory div').show();
	});
}

function elderPayRecord_findCostInventoryBybeHospitalId() {
	if($('#vue_vm_list_inventory div').length==0) {return;}
	$('#vue_vm_list_inventory div').hide();
	var startYear = $('#startYear').val();
	var startMonth = $('#startMonth').val();
	var startDay = $('#startDay').val();
	var endYear = $('#endYear').val();
	var endMonth = $('#endMonth').val();
	var endDay = $('#endDay').val();
	var startTime = getStandardDay(startYear, startMonth, startDay);
	var endTime = getStandardDay(endYear, endMonth, endDay);
	
	if(isEmpty(startYear)) {
		alert('请输入开始年');
		return;
	}
	if(isEmpty(startMonth)) {
		alert('请选择开始月');
		return;
	}
	if(isEmpty(startDay)) {
		alert('请选择开始日');
		return;
	}
	if(isEmpty(endYear)) {
		alert('请输入结束年');
		return;
	}
	if(isEmpty(endMonth)) {
		alert('请选择结束月');
		return;
	}
	if(isEmpty(endDay)) {
		alert('请选择结束日');
		return;
	}
	if(isEmpty(startTime)) {
		alert('请输入开始时间');
		return;
	}
	if(isEmpty(endTime)) {
		alert('请输入结束时间');
		return;
	}
	if(isEmpty(elderBeHospital.beHospitalId)) {
		alert('请选择长者');
		return;
	}
	if(elderBeHospital.beHospitalId=='beHospitalId-none') {
		alert('该长者未入住');
		return;
	}
	
	var yearMonth = null;

	find_basic_by_json(path+'/elderPayRecord/findCostInventoryBybeHospitalId',
			{beHospitalId:elderBeHospital.beHospitalId, dateSince:startTime, dateEnd:endTime}, function(response) {
		$('#vue_vm_list_inventory').html(gl_vue_vm_list_inventory_html);
		
		new Vue({
			el: '#vue_vm_list_inventory',
			data: {
				todos: response.data
			},
			methods: {
				getTitle:function() {
					return startTime+'至'+endTime;
				},
				openTotalPage:function() {
					openTotalPageByTimeInterval(elderBeHospital.beHospitalId, startTime, endTime);
				},
				openPrintPage:function(paperType) {
					openPrintPageByMonth(elderBeHospital.beHospitalId, yearMonth, paperType);
				},
				getElderPayRecordTotalMoney:function(forms) {
					var totalMoney = 0;
					
					if(forms) {
						for(var i=0; i<forms.length; i++) {
                            if(forms[i].payWay==3){//如果是vip卡扣费
                                continue;
                            }
							totalMoney += forms[i].payMoney;
						}
					}
					
					return totalMoney;
				},
				getElderArrearageTotalMoney:function(forms) {
					var totalMoney = 0;
					
					if(forms) {
						for(var i=0; i<forms.length; i++) {
							totalMoney += forms[i].arrearageMoney;
						}
					}
					
					return totalMoney;
				}
			}
		});
		
		$('#vue_vm_list_inventory div').show();
	});
}

function openTotalPage_buda(beHospitalId,startTime,endTime) {
	var pageParam = {};
	pageParam.type = 'buda';
	pageParam.beHospitalId = beHospitalId;
    pageParam.startTime = startTime;
    pageParam.endTime = endTime;

	window.open('6-2-10paylist-total.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
}

function openPrintPage_buda(beHospitalId, paperType,startTime, endTime) {
	var pageParam = {};
	pageParam.relationId = beHospitalId+"-outHospital";
	pageParam.paperType = paperType;
	pageParam.type = 'buda';
	pageParam.beHospitalId = beHospitalId;
    pageParam.startTime = startTime;
    pageParam.endTime = endTime;
	
	if(paperType==1) {
		window.open('0_print_fp.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
	}else if(paperType==3||paperType==5) {
		window.open('0_print_sj.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
	}
}

function openTotalPageByTimeInterval(beHospitalId, startTime, endTime) {
	var pageParam = {};
	pageParam.type = 'timeInterval';
	pageParam.beHospitalId = beHospitalId;
	pageParam.startTime = startTime;
	pageParam.endTime = endTime;
	
	window.open('6-2-10paylist-total.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
}

function openTotalPageByMonth(beHospitalId, yearMonth) {
	var pageParam = {};
	pageParam.type = 'month';
	pageParam.beHospitalId = beHospitalId;
	pageParam.yearMonth = yearMonth;
	
	window.open('6-2-10paylist-total.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
}

function openTotalPageByDay(beHospitalId, yearMonthDay) {
	var pageParam = {};
	pageParam.type = 'day';
	pageParam.beHospitalId = beHospitalId;
	pageParam.yearMonthDay = yearMonthDay;
	
	window.open('6-2-10paylist-total.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
}

function openPrintPageByMonth(beHospitalId, yearMonth, paperType) {
	var pageParam = {};
	pageParam.relationId = beHospitalId;
	pageParam.paperType = paperType;
	pageParam.type = 'month';
	pageParam.beHospitalId = beHospitalId;
	pageParam.yearMonth = yearMonth;
	
	if(paperType==1) {
		window.open('0_print_fp.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
	}else if(paperType==3) {
		window.open('0_print_sj_other.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
	}
}

function openPrintPageByDay(beHospitalId, yearMonthDay, paperType) {
	var pageParam = {};
	pageParam.relationId = beHospitalId;
	pageParam.paperType = paperType;
	pageParam.type = 'day';
	pageParam.beHospitalId = beHospitalId;
	pageParam.yearMonthDay = yearMonthDay;
	
	if(paperType==1) {
		window.open('0_print_fp.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
	}else if(paperType==3) {
		window.open('0_print_sj_other.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
	}
}

function openPrintPage_out(beHospitalId, paperType,data) {
	var pageParam = {};
	pageParam.relationId = beHospitalId+"-outHospital";
	pageParam.paperType = paperType;
	pageParam.type = 'out';
	pageParam.beHospitalId = beHospitalId;
    pageParam.pledge = data.outFeeRecordForm.pledge?data.outFeeRecordForm.pledge:0;
    pageParam.totalFee = data.outFeeRecordForm.totalFee?data.outFeeRecordForm.totalFee:0;
    pageParam.totalPay = data.outFeeRecordForm.totalPay?data.outFeeRecordForm.totalPay:0;
    pageParam.moneyMealCard = data.outFeeRecordForm.moneyMealCard?data.outFeeRecordForm.moneyMealCard:0;
    pageParam.amount = pageParam.totalFee;
    pageParam.beHospitalId = beHospitalId;
	if(paperType==1) {
		window.open('0_print_fp.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
	}else if(paperType==3||paperType==5) {
		window.open('0_print_sj.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
	}
}

function openHistoryPage() {
	window.open('3-7-9ls.html');
}

function deleteBatch() {
	deleteBatch_basic(path+'/elderPayRecord/deleteBatch');
}
